/*

Illustration of theretical model

Output: Figures B.2, B.3

*/

cap program drop fcts 
program fcts, rclass
	
	/* draw functions depending on model parameters */ 
	
	// thresholds
	local z0 "(b-u)/g"
	local z1 "(b-u-e)/(g*x)"
	local u0 "b/g"
	local u1 "(b-e)/(g*x)"
	
	// discontinuities
	return local null	= (b-u-e)/g // null of mail-in curve	
	return local q1 = (b-u-e)/(b-u)
	return local s  = (b-e)/b
	return local q2 = (b-e)/(b-u)

	* Polling place
		// t=0
		return local P0 	"(`z0'+(1-a)*(`u0'-`z0'))"

		// t=1 (no IA)
		return local P1no	"(`z1'+(1-a)*(`u1'-`z1'))"

		// t=1 inattention
		return local P1_1 "( `z1'+a*t*(`u1'-`z1')+(1-a)*(`u1'-`z1'))"
		return local P1_2 "( `z1'+a*t*(`z0'-`z1') + (1-a)*(`u1'-`z1'))"
		return local P1_3 "( `z1'+a*t*(`z0'-`z1')+(1-a)*(`u1'-`z1') - p*(1-a)*(`u1'-`u0') )"
		return local P1_4 "( `z1'+(1-a)*(`u1'-`z1') - p*(1-a)*(`u1'-`u0'))"
		
	* Mail-in
		// t=0
		return local M0 "(a*(1-`z0'))"
	
		// t=1 (no IA)
		return local M1no "a*(1-`z1')"
		
		// t=1 inattention
		return local M1_1 "(a*(1-`z1')-t*a*(`z0'-`z1'))"
		return local M1_2 "(a*(1-`z1'))"		 
		
	* total
		// t=0
		return local T0	"(`u0'+a*(1-`u0'))"
		
		// t=1 (no IA)
		return local T1no 	"(`u1'+a*(1-`u1'))"
		
		// t=1 inattention
		return local T1_1 	"(`u1'+(1-t)*a*(`z0'-`u1')+a*(1-`z0'))"
		return local T1_2 	"(`u1'+a*(1-`u1'))"
		return local T1_3 	"(`u1'+a*(1-`u1')-p*(1-a)*(`u1'-`u0'))"
end	

*** CASE 1: no inattention , t=0, p=0

 * Set model model parameters
	scalar b 		= 100 	// Benefit
	scalar g		= 160 	// distance pref parameter, gamma, g > B !
	scalar c		= 70	// cost of mail-in voting (low)
	scalar e 		= 60	// search cost, e < c !
	scalar u 		= b-c	// net utility mail-in
	scalar t		= 0 	// share inattentive polling place voters in period 0, P0
	scalar p 		= 0		// share inattentive abstainers in period 0, A0
	scalar a		= c/g + .1	// share mail-in voters, a > c/g ! (otherwise no Mail in t=0)
	assert inrange(a,0,1)
	
	// functions 
	fcts 
	 

* Plot: Figure B2. No inattention
tw	(function `r(T1no)'/`r(T0)', range(0.08 2) 				lcol(black) lpat(solid)) 	///
	(function `r(T1_3)'/`r(T0)', range(0.08 `r(s)') 		lcol(black) lpat(-....-)) 	///
	(function `r(T1_2)'/`r(T0)', range(`r(s)' `r(q2)') 		lcol(black) lpat(-....-)) 	///
	(function `r(T1_1)'/`r(T0)', range(`r(q2)' 2) 			lcol(black) lpat(-....-)) 	///	
	(function `r(M1no)'/`r(M0)', range(`r(null)' 2) 		lcol(cranberry) lpat(solid)) 	///
	(function `r(M1_2)'/`r(M0)', range(`r(null)' `r(q1)') 	lcol(cranberry) lpat(-....-)) ///
	(function `r(M1_1)'/`r(M0)', range(`r(q1)' 2) 			lcol(cranberry) lpat(-....-)) ///
	(function 0*x, range(0 `r(null)' ) 						lcol(cranberry) lpat(solid)) ///		
	(function `r(P1no)'/`r(P0)', range(0.08 2) 				lcol(blue) lpat(solid)) 	///
	(function `r(P1_4)'/`r(P0)', range(0.08 `r(q1)') 		lcol(blue) lpat(-....-)) ///
	(function `r(P1_3)'/`r(P0)', range(`r(q1)' `r(s)') 		lcol(blue) lpat(-....-)) ///
	(function `r(P1_2)'/`r(P0)', range(`r(s)' `r(q2)') 		lcol(blue) lpat(-....-)) ///
	(function `r(P1_1)'/`r(P0)', range(`r(q2)' 2) 			lcol(blue) lpat(-....-)) ///
	, legend(size(small) order(1 "total " 5 "mail"  9 "in person") pos(1) ring(0) row(3) title("Turnout")) ///
	ytitle("Turnout in Period 1 relative to Period 0",size(medium)) xtitle("Distance in Period 1 relative to Period 0", size(medium)) ///
	xlabel(0 "0" 1 "1" 2 " ") ylabel(0 "0" 1 "1" 4 " ") ///
	xline(1, lpat(solid) lcol(gray%50)) yline(1, lpat(solid) lcol(gray%50)) yla(,nogrid) xla(,nogrid)
	gr_edit .legend.title.DragBy 0 -4
	graph export "$figures/Figure_B2_theory_rel_turnout_noIA.pdf", replace

	
	
*** CASE 2: only in-person voters inattentive , t>0, p=0

 * Set model model parameters
	scalar b 		= 100 	// Benefit
	scalar g		= 160 	// distance pref parameter, gamma, g > B !
	scalar c		= 70	// cost of mail-in voting (low)
	scalar e 		= 60	// search cost, e < c !
	scalar u 		= b-c	// net utility mail-in
	scalar t		= 0.5 	// share inattentive polling place voters in period 0, P0	
	scalar p 		= 0		// share inattentive abstainers in period 0, A0
	scalar a		= c/g + .1	// share mail-in voters, a > c/g ! (otherwise no Mail in t=0)
	assert inrange(a,0,1)
	
	// functions 
	fcts 

* Plot: Figure B3a. Only pp voters inattentive
tw	(function `r(T1no)'/`r(T0)', range(0.08 2) 				lcol(black) lpat(solid)) 	///
	(function `r(T1_3)'/`r(T0)', range(0.08 `r(s)') 		lcol(black) lpat(-....-)) 	///
	(function `r(T1_2)'/`r(T0)', range(`r(s)' `r(q2)') 		lcol(black) lpat(-....-)) 	///
	(function `r(T1_1)'/`r(T0)', range(`r(q2)' 2) 			lcol(black) lpat(-....-)) 	///	
	(function `r(M1no)'/`r(M0)', range(`r(null)' 2) 		lcol(cranberry) lpat(solid)) 	///
	(function `r(M1_2)'/`r(M0)', range(`r(null)' `r(q1)') 	lcol(cranberry) lpat(-....-)) ///
	(function `r(M1_1)'/`r(M0)', range(`r(q1)' 2) 			lcol(cranberry) lpat(-....-)) ///
	(function 0*x, range(0 `r(null)' ) 						lcol(cranberry) lpat(solid)) ///		
	(function `r(P1no)'/`r(P0)', range(0.08 2) 				lcol(blue) lpat(solid)) 	///
	(function `r(P1_4)'/`r(P0)', range(0.08 `r(q1)') 		lcol(blue) lpat(-....-)) ///
	(function `r(P1_3)'/`r(P0)', range(`r(q1)' `r(s)') 		lcol(blue) lpat(-....-)) ///
	(function `r(P1_2)'/`r(P0)', range(`r(s)' `r(q2)') 		lcol(blue) lpat(-....-)) ///
	(function `r(P1_1)'/`r(P0)', range(`r(q2)' 2) 			lcol(blue) lpat(-....-)) ///
	, legend(size(small) order(1 "total (no IA)" 2 "total (IA)" 5 "mail (no IA)" 6 "by mail (IA)" 9 "in person (no IA)" 10 "in person (IA)") pos(1) ring(0) row(3) title("Turnout")) ///
	ytitle("Turnout in Period 1 relative to Period 0",size(medium)) xtitle("Distance in Period 1 relative to Period 0", size(medium)) ///
	xlabel(0 "0" 1 "1" 2 " ") ylabel(0 "0" 1 "1" 4 " ") ///
	xline(1, lpat(solid) lcol(gray%50)) yline(1, lpat(solid) lcol(gray%50)) yla(,nogrid) xla(,nogrid)
	graph export "$figures/Figure_B3a_theory_rel_turnout_IA1.pdf", replace
	
	

*** CASE 3: inattentive in-person voters and abstainers, t>0, p>0

 * Set model model parameters
	scalar b 		= 100 	// Benefit
	scalar g		= 160 	// distance pref parameter, gamma, g > B !
	scalar c		= 70	// cost of mail-in voting (low)
	scalar e 		= 60	// search cost, e < c !
	scalar u 		= b-c	// net utility mail-in
	scalar t		= 0.5 	// share inattentive polling place voters in period 0, P0
	scalar p 		= 0.2		// share inattentive abstainers in period 0, A0
	scalar a		= c/g + .1	// share mail-in voters, a > c/g ! (otherwise no Mail in t=0)
	assert inrange(a,0,1)
	
	// functions 
	fcts 

* Plot: Figure B3b. abstainers and pp voters inattentive
tw	(function `r(T1no)'/`r(T0)', range(0.08 2) 				lcol(black) lpat(solid)) 	///
	(function `r(T1_3)'/`r(T0)', range(0.08 `r(s)') 		lcol(black) lpat(-....-)) 	///
	(function `r(T1_2)'/`r(T0)', range(`r(s)' `r(q2)') 		lcol(black) lpat(-....-)) 	///
	(function `r(T1_1)'/`r(T0)', range(`r(q2)' 2) 			lcol(black) lpat(-....-)) 	///	
	(function `r(M1no)'/`r(M0)', range(`r(null)' 2) 		lcol(cranberry) lpat(solid)) 	///
	(function `r(M1_2)'/`r(M0)', range(`r(null)' `r(q1)') 	lcol(cranberry) lpat(-....-)) ///
	(function `r(M1_1)'/`r(M0)', range(`r(q1)' 2) 			lcol(cranberry) lpat(-....-)) ///
	(function 0*x, range(0 `r(null)' ) 						lcol(cranberry) lpat(solid)) ///		
	(function `r(P1no)'/`r(P0)', range(0.08 2) 				lcol(blue) lpat(solid)) 	///
	(function `r(P1_4)'/`r(P0)', range(0.08 `r(q1)') 		lcol(blue) lpat(-....-)) ///
	(function `r(P1_3)'/`r(P0)', range(`r(q1)' `r(s)') 		lcol(blue) lpat(-....-)) ///
	(function `r(P1_2)'/`r(P0)', range(`r(s)' `r(q2)') 		lcol(blue) lpat(-....-)) ///
	(function `r(P1_1)'/`r(P0)', range(`r(q2)' 2) 			lcol(blue) lpat(-....-)) ///
	, legend(size(small) order(1 "total (no IA)" 2 "total (IA)" 5 "mail (no IA)" 6 "by mail (IA)" 9 "in person (no IA)" 10 "in person (IA)") pos(1) ring(0) row(3) title("Turnout")) ///
	ytitle("Turnout in Period 1 relative to Period 0",size(medium)) xtitle("Distance in Period 1 relative to Period 0", size(medium)) ///
	xlabel(0 "0" 1 "1" 2 " ") ylabel(0 "0" 1 "1" 4 " ") ///
	xline(1, lpat(solid) lcol(gray%50)) yline(1, lpat(solid) lcol(gray%50)) yla(,nogrid) xla(,nogrid)
	graph export "$figures/Figure_B3b_theory_rel_turnout_IA2.pdf", replace








